package com.jadows.tdog.server;


import com.jadows.tdog.server.exceptions.ChatServerException;
import com.jadows.tdog.server.option.ChatServerOption;

/**
 * 单例工厂
 */
class ChatServerFactory {

    private ChatServer chatServer = null;

    private ChatServerFactory() {
    }

    static ChatServerFactory getInstance() {
        return ChatServerFactoryInstance.INSTANCE;
    }

    synchronized ChatServer newChatServer(ChatServerOption option) {
        if (chatServer == null) {
            chatServer = new NettyChatServer(option == null ? new ChatServerOption() : option);
            return chatServer;
        }
        throw new ChatServerException("server has been created already, instance : [" + chatServer + "]!");
    }

    private static class ChatServerFactoryInstance {
        private static final ChatServerFactory INSTANCE = new ChatServerFactory();
    }

}
